<template>
  <div>
    <van-nav-bar left-arrow @click-left="onClickLeft" title="收货地址" />
    <van-address-edit
      :area-list="areaList"
      show-postal
      show-delete
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import { getCurUserId, addRessadd,checktoken } from "../request/api.js";
import { areaList } from "@vant/area-data";
import { Toast } from "vant";
export default {
  data() {
    return {
      areaList,
      searchResult: [],
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onSave(d) {
      console.log(d);
      let uid = getCurUserId();
      let obj = {
        uid,
        username: d.name,
        userphone: d.tel,
        regioncode: d.postalCode,
        location: d.county,
        useraddress: d.addressDetail,
      };
      addRessadd(obj)
        .then((d) => {
          if (d.data.code == 200) {
            this.$toast({
              message: "添加成功",
            });
            this.$router.go(-1)
          }
          // console.log(d, 9999999);
        })
        .catch((e) => {
          console.log(e);
        });
    },
    onDelete() {
      Toast("删除成功");
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: "黄龙万科中心",
            address: "杭州市西湖区",
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
  },

};
</script>

<style scoped>
::v-deep .van-nav-bar__content {
  background-color: #ff6345;
}
::v-deep .van-button--danger {
  color: #fff;
  background-color: #ff6345;
}
::v-deep .van-nav-bar__title {
  font-weight: bold;
  color: white;
}
::v-deep .van-nav-bar .van-icon {
  color: white;
  font-weight: bold;
}
</style>